// pages/user/order/list/list.js
import {
  getOrderList
} from '../../../../api/order.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    arrowUp: true,
    selectOptions: ['全部', '课程', '证书', '会员','活动'],
    selectIndex: 0,
    list: [],
    rowCount: 0,
    badge: false,
    page:1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getData();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      badge: getApp().globalData.unRead.invoice.length > 0
    })
  },

  jumpToInvoice() {
    wx.navigateTo({
      url: '/pages/user/order/invoice/invoice',
    })
  },

  jumpToRecord() {
    wx.navigateTo({
      url: '/pages/user/order/record/record',
    })
  },

  getData() {
    getOrderList({productType:this.data.selectIndex -1,page:this.data.page,size:10}).then(res => {
      this.setData({
        list: this.data.list.concat(res.list),
        rowCount: res.rowCount
      })
    })
  },

  handleScrollBottom(e) {
    if (this.data.rowCount > this.data.list.length) {
      this.setData({
        page:this.data.page+=1
      })
      this.getData();
    }
  },

  /**
   * 选择框 - 选择
   * @param {object} e 
   */
  handleSelect(e) {
    this.setData({
      selectIndex: Number(e.currentTarget.dataset.index),
      arrowUp: true
    })
    this.data.page = 1;
    this.data.list.length = 0;
    this.getData();
  },

  /**
   * 选择框展示
   */
  handleArrowUp() {
    this.setData({
      arrowUp: !this.data.arrowUp
    })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})